﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using CSharpTest.Net.Serialization;

namespace TEAA
{
    public class RecordIDListSerializer : ISerializer<List<RecordID>>
    {

        void ISerializer<List<RecordID>>.WriteTo(List<RecordID> value, Stream stream)
        {
            PrimitiveSerializer.Int32.WriteTo(value.Count, stream);

            foreach (RecordID rid in value)
            {
                PrimitiveSerializer.UInt32.WriteTo(rid.page, stream);
                PrimitiveSerializer.UInt32.WriteTo(rid.slot, stream);
            }
        }

        List<RecordID> ISerializer<List<RecordID>>.ReadFrom(Stream stream)
        {
            int size = PrimitiveSerializer.Int32.ReadFrom(stream);
            List<RecordID> values = new List<RecordID>(size);

            for (int i = 0; i < size; i++)
            {
                RecordID rid = new RecordID(PrimitiveSerializer.UInt32.ReadFrom(stream), PrimitiveSerializer.UInt32.ReadFrom(stream));
                values.Add(rid);
            }

            return values;
        }

    }
}
